// 云函数入口文件
const cloud = require('wx-server-sdk')

// 使用当前云环境
cloud.init({
    env: cloud.DYNAMIC_CURRENT_ENV
})

// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()
    const result = await cloud.openapi.wxacode.getUnlimited({
        scene: wxContext.OPENID,
        // page: "pages/blog/blog"
        // lineColor: {
        //   'r': 211,
        //   'g': 60,
        //   'b': 57
        // },
        // isHyaline: true
    })

    const upload = await cloud.uploadFile({
        cloudPath: 'qrcode/' + Date.now() + '-' + Math.random() + '.png',
        fileContent: result.buffer
    })

    return upload.fileID
}